home *** CD-ROM | disk | FTP | other *** search
/ By Popular Request 2.0 / By Popular Request 2.0 (Arsenal Computer).ISO / amiga_6 / tiffdtyp.lha / sources / classbase.c < prev    next >
C/C++ Source or Header  |  1995-03-15  |  3KB  |  137 lines

  1. /* classbase.c
  2.  *
  3.  */
  4.  
  5. #include "classbase.h"
  6.  
  7. /*****************************************************************************/
  8.  
  9. #define    DB(x)    x;
  10.  
  11. /*****************************************************************************/
  12.  
  13. Class *ASM ObtainBMPEngine (REG (a6) struct ClassBase *cb)
  14. {
  15.     return (cb->cb_Class);
  16. }
  17.  
  18. /*****************************************************************************/
  19.  
  20. struct Library *ASM LibInit (REG (d0) struct ClassBase *cb, REG (a0) BPTR seglist, REG (a6) struct Library * sysbase)
  21. {
  22.     cb->cb_SegList = seglist;
  23.     cb->cb_SysBase = sysbase;
  24.     InitSemaphore (&cb->cb_Lock);
  25.     if (cb->cb_SysBase->lib_Version >= 39)
  26.     {
  27.     cb->cb_IntuitionBase = OpenLibrary ("intuition.library",39);
  28.     cb->cb_GfxBase       = OpenLibrary ("graphics.library", 39);
  29.     cb->cb_DOSBase       = OpenLibrary ("dos.library",      39);
  30.     cb->cb_UtilityBase   = OpenLibrary ("utility.library",  39);
  31.  
  32.     DB (KPrintF ("inited library\n"));
  33.  
  34.     return cb;
  35.     }
  36.     else
  37.     {
  38.     DB (KPrintF ("could not init library\n"));
  39.     return NULL;
  40.     }
  41. }
  42.  
  43. /*****************************************************************************/
  44.  
  45. LONG ASM LibOpen (REG (a6) struct ClassBase *cb)
  46. {
  47.     LONG retval = (LONG) cb;
  48.     BOOL success = TRUE;
  49.  
  50.     ObtainSemaphore (&cb->cb_Lock);
  51.  
  52.     /* Use an internal use counter */
  53.     cb->cb_Lib.lib_OpenCnt++;
  54.     cb->cb_Lib.lib_Flags &= ~LIBF_DELEXP;
  55.  
  56.     if (cb->cb_Lib.lib_OpenCnt == 1)
  57.     {
  58.     if (cb->cb_Class == NULL)
  59.     {
  60.         success = FALSE;
  61.         if (cb->cb_IFFParseBase = OpenLibrary ("iffparse.library", 39))
  62.         if (cb->cb_DataTypesBase = OpenLibrary ("datatypes.library", 39))
  63.             if (cb->cb_SuperClassBase = OpenLibrary ("datatypes/picture.datatype", 39))
  64.             if (cb->cb_Class = initClass (cb))
  65.                 success = TRUE;
  66.     }
  67.     }
  68.  
  69.     if (!success)
  70.     {
  71.     DB (KPrintF ("could not open library\n"));
  72.     CloseLibrary (cb->cb_SuperClassBase);
  73.     CloseLibrary (cb->cb_DataTypesBase);
  74.     CloseLibrary (cb->cb_IFFParseBase);
  75.     cb->cb_IFFParseBase = cb->cb_DataTypesBase = cb->cb_SuperClassBase = NULL;
  76.  
  77.     cb->cb_Lib.lib_OpenCnt--;
  78.     retval = NULL;
  79.     }
  80.     else
  81.     {
  82.     DB (KPrintF ("opened library\n"));
  83.     }
  84.  
  85.     ReleaseSemaphore (&cb->cb_Lock);
  86.  
  87.     return (retval);
  88. }
  89.  
  90. /*****************************************************************************/
  91.  
  92. LONG ASM LibClose (REG (a6) struct ClassBase *cb)
  93. {
  94.     LONG retval = NULL;
  95.  
  96.     ObtainSemaphore (&cb->cb_Lock);
  97.  
  98.     if (cb->cb_Lib.lib_OpenCnt)
  99.     cb->cb_Lib.lib_OpenCnt--;
  100.  
  101.     if ((cb->cb_Lib.lib_OpenCnt == 0) && cb->cb_Class)
  102.     {
  103.     if (FreeClass (cb->cb_Class))
  104.     {
  105.         cb->cb_Class = NULL;
  106.         CloseLibrary (cb->cb_SuperClassBase);
  107.         CloseLibrary (cb->cb_DataTypesBase);
  108.         CloseLibrary (cb->cb_IFFParseBase);
  109.     }
  110.     else
  111.     {
  112.         cb->cb_Lib.lib_Flags |= LIBF_DELEXP;
  113.     }
  114.     }
  115.  
  116.     if (cb->cb_Lib.lib_Flags & LIBF_DELEXP)
  117.     retval = LibExpunge (cb);
  118.  
  119.     ReleaseSemaphore (&cb->cb_Lock);
  120.  
  121.     return (retval);
  122. }
  123.  
  124. /*****************************************************************************/
  125.  
  126. LONG ASM LibExpunge (REG (a6) struct ClassBase *cb)
  127. {
  128.     Remove ((struct Node *) cb);
  129.  
  130.     CloseLibrary (cb->cb_UtilityBase);
  131.     CloseLibrary (cb->cb_DOSBase);
  132.     CloseLibrary (cb->cb_GfxBase);
  133.     CloseLibrary (cb->cb_IntuitionBase);
  134.  
  135.     return ((LONG) cb->cb_SegList);
  136. }
  137.